//
//  CustomView.m
//  UI_Block
//
//  Created by Scott on 16/1/21.
//  Copyright © 2016年 Scott. All rights reserved.
//

#import "CustomView.h"

@interface CustomView ()

@property (retain, nonatomic) IBOutlet UIView *view;

@property (nonatomic, copy) void(^block)(CustomView *view);

@end

@implementation CustomView


- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    
    self = [super initWithCoder:aDecoder ];
    if (self) {
        
        [[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:self options:nil];
        
        self.view.frame = self.bounds;
        [self addSubview:self.view];
        
    }
    
    return self;
}



- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    NSLog(@"%ld", self.retainCount);
    self.block(self);
    NSLog(@"%ld", self.retainCount);
}


- (void)viewDidClick:(void (^)(CustomView *))block {
    
    NSLog(@"%ld", self.retainCount);
    
    self.block = block;
    
    NSLog(@"%ld", self.retainCount);
}



- (IBAction)handleButtonAction:(id)sender {
    
    self.block(self);
    
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)dealloc {
    [_view release];
    [super dealloc];
}
@end
